#ifndef __OC_ServerTimer_H__
#define __OC_ServerTimer_H__

#include "ServerDef.h"
#include "ServerUtil.h"

namespace OCPP
{
#define SeceondsPerDay 86400
#define SeceondsPerHour 3600
#define SeceondsPerMinute 60

	class _ServerExport ServerTimer
	{
	public:
		virtual ~ServerTimer() {}
		void startTimer();

		void setFetchSeconds(uint32 value) { fetchSeconds = value; }
		uint32 getFetchSeconds() { return fetchSeconds; }

		void setClearSeconds(uint32 value) { clearSeconds = value; }
		uint32 getClearSeconds() { return clearSeconds; }

		void setDataPath(String value) { dataPath = value; }
		String getDataPath() { return dataPath; }

		void setCachePath(String value) { cachePath = value; }
		String getCachePath() { return cachePath; }
		
		void setName(String value) { name = value; }
		String getName() { return name; }

		virtual String db_query_latest();
		virtual String db_query_start();
		virtual std::set<String> db_query(String startTime, String endTime);
		static bool removeDir(String dir);
	protected:
		String getUtcDateString();
		String getUtcDateTimeString();

		String getDateString();
		String getDateTimeString();

		String toUtcDateString(Date date);
		String toUtcDateTimeString(Date date);
		String toUtcDateTimeYearMonthDayHourString(Date date);
		String toUtcDateTimeYearMonthDayHourMinuteString(Date date);

		String toDateString(Date date);
		String toDateTimeString(Date date);
		String toDateTimeYearMonthDayHourString(Date date);
		String toDateTimeYearMonthDayHourMinuteString(Date date);

		Date dateFromString(String dateTime);
		Date utcDateFromString(String dateTime);

		virtual void doJob();
		virtual void clearCache();

		virtual bool createDb();
		virtual int db_insert_dateTime(String dateTime);
		virtual void db_clear_before_dateTime(String dateTime);
		virtual void db_clear_before_dateTime(Date dateTime);

		uint32 fetchSeconds = 0;
		uint32 clearSeconds = 0;
		String dataPath;
		String cachePath;
		String name;
		bool needClearCache = false;
	};
}

#endif